import React from 'react';
import Reflux from 'reflux';
import * as ReactMixin from "react-mixin";
import {ActivityIndicator, List} from "antd-mobile";
import Store from "./Store";
import Actions from "./Actions";
import YwhtpItem from "../../../../components/ywhtp/YwhtpItem";
import Loading from "../../../../components/loading/Loading";

class YwhXj extends React.Component{
  constructor(props) {
    super(props);
  }

  componentWillMount() {
    Actions.defaultInit(this.props.params);
  }

  render() {

    let rw = this.state.YwhXj.rw;
    let dyzRws, ldzRws, wyRws, zrRws;
    if (rw.CAST01.isLoading) {
      dyzRws = <Loading text="数据获取中" />;
    } else {
      if (rw.CAST01.data.length > 0) {
        dyzRws = rw.CAST01.data.map(rw => <YwhtpItem courtName={this.state.YwhXj.court.name} rw={rw} />);
      } else {
        dyzRws = <div className="no-data-div">暂无数据</div>;
      }
    }

    if (rw.CAST02.isLoading) {
      ldzRws = <Loading text="数据获取中" />;
    } else {
      if (rw.CAST02.data.length > 0) {
        ldzRws = rw.CAST02.data.map(rw => <YwhtpItem courtName={this.state.YwhXj.court.name} rw={rw} />);
      } else {
        ldzRws = <div className="no-data-div">暂无数据</div>;
      }
    }

    if (rw.CAST03.isLoading) {
      wyRws = <Loading text="数据获取中" />;
    } else {
      if (rw.CAST03.data.length > 0) {
        wyRws = rw.CAST03.data.map(rw => <YwhtpItem courtName={this.state.YwhXj.court.name} rw={rw} />);
      } else {
        wyRws = <div className="no-data-div">暂无数据</div>;
      }
    }

    if (rw.CAST04.isLoading) {
      zrRws = <Loading text="数据获取中" />;
    } else {
      if (rw.CAST04.data.length > 0) {
        zrRws = rw.CAST04.data.map(rw => <YwhtpItem courtName={this.state.YwhXj.court.name} rw={rw} />);
      } else {
        zrRws = <div className="no-data-div">暂无数据</div>;
      }
    }

    return (
      <div>
        <List renderHeader={() => "单元长选举"}>{dyzRws}</List>
        <List renderHeader={() => "楼栋长选举"}>{ldzRws}</List>
        <List renderHeader={() => "委员选举"}>{wyRws}</List>
        <List renderHeader={() => "主任选举"}>{zrRws}</List>
      </div>
    );
  }
}

ReactMixin.onClass(YwhXj, Reflux.connect(Store, 'YwhXj'));

export default YwhXj;
